#ifndef SIMPLESTRINGKEY_H_
#define SIMPLESTRINGKEY_H_

#include <string>

#include "../record.h"
#include "../binarystream.h"

class StringKey: public Key {

public:
        StringKey() {
    }

        StringKey(std::string id) {
        this->id = id;
    }

    virtual void read(BinaryStream& in) {
        id = in.readString();
    }

    virtual void write(BinaryStream& out) {
        out.writeString(id);
    }

    virtual int8_t compareTo(const Key* that) {
        return this->id.compare( ((StringKey*)that)->id );
    }

    virtual u_int32_t hashcode(){
        u_int32_t hash = 2166136261u;
        for (auto it = id.begin(); it != id.end(); ++it)
            hash = (hash * 16777619) ^ *it;
        return hash;
    }

    virtual std::string toString(){
        return id;
    }

private:

    std::string id;
};

#endif /* SIMPLESTRINGKEY_H_ */
